//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nccloud.web.obm.ebankdfgz.action;

import java.util.ArrayList;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.vo.obm.payroll.DfgzBillVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nccloud.dto.obm.ebankdfgz.vo.DfgzDeleteInfoVO;
import nccloud.framework.core.json.IJson;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.json.JsonFactory;
import nccloud.web.obm.common.ObmActionUtil;
import nccloud.web.workflow.approve.util.NCCFlowUtils;

public class EbankDfgzCommitAction implements ICommonAction {
    public EbankDfgzCommitAction() {
    }

    public Object doAction(IRequest request) {
        Object[] result = null;
        String str = request.read();
        IJson json = JsonFactory.create();
        DfgzDeleteInfoVO info = (DfgzDeleteInfoVO)json.fromJson(str, DfgzDeleteInfoVO.class);
        BillQuery<DfgzBillVO> query = new BillQuery(DfgzBillVO.class);
        String[] ids = info.getId().split(",");
        String[] tss = info.getTs().split(",");
        DfgzBillVO[] billvos = (DfgzBillVO[])query.query(ids);

        for(int i = 0; i < ids.length; ++i) {
            billvos[i].getParentVO().setTs(new UFDateTime(tss[i]));
        }

        ArrayList<DfgzBillVO> approveVOList = new ArrayList();
        ArrayList<DfgzBillVO> commitVOList = new ArrayList();
        if (billvos != null && billvos.length > 0) {
            try {
                this.getCommitOrApproveVOList(billvos, approveVOList, commitVOList);
            } catch (BusinessException var13) {
            }
        }

        if (approveVOList != null && approveVOList.size() > 0) {
            result = ObmActionUtil.CommitNoFlow((AbstractBill[])approveVOList.toArray(new DfgzBillVO[0]), "36C9", "SAVE");
        }

        if (commitVOList != null && commitVOList.size() > 0) {
            result = ObmActionUtil.cloudContext((AbstractBill[])commitVOList.toArray(new DfgzBillVO[0]), "36C9", "SAVE");
        }

        return result;
    }

    private void getCommitOrApproveVOList(DfgzBillVO[] bills, ArrayList<DfgzBillVO> approveVOList, ArrayList<DfgzBillVO> commitVOList) throws BusinessException {
        DfgzBillVO[] var4 = bills;
        int var5 = bills.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            DfgzBillVO bill = var4[var6];
            boolean isapproveflow = NCCFlowUtils.hasApproveflowDef("36C9", bill);
            if (isapproveflow) {
                commitVOList.add(bill);
            } else {
                approveVOList.add(bill);
            }
        }

    }
}
